import Ember from "ember";
import config from "game-front/config/environment";
import RSVP from 'rsvp';

export default Ember.Route.extend({
	share: Ember.inject.service(),
	beforeModel: function (posts, transition) {
		Ember.run.scheduleOnce('afterRender', this, function () {
			Ember.$(".user-background").height(document.body.scrollHeight);
		});
	},
	model(params) {
		var userInfo = this.modelFor("application");
		return RSVP.hash({
			winners: Ember.$.getJSON(config.apiBase + "rankings/last", {
				userId: userInfo ? userInfo.userId : 'none',
				gameZoneProductId: params.gameZoneProductId
			}),
			gameZoneProductId:params.gameZoneProductId
		});
	},
	afterModel(model) {
		console.log(model);
		var share = this.get("share");
		var userId = sessionStorage.getItem("userId");
		var link = window.location.origin + config.baseURL + "beforewinnersshare?key=" + userId;

		var shareLink = {
			title: `${model.winners.issueWinner.productName}-上期获奖名单`, // 分享标题
			desc: '获奖名单来了，快来膜拜一下吧',
			link: link + "#public=true", // 分享链接
			imgUrl: 'http://game.inkanke.com/yydb/assets/images/banner.png', // 分享图标
			success: function () {
				share.reward(userId);

			},
			cancel: function () {
				// 用户取消分享后执行的回调函数
			}
		};
		share.config(shareLink);
	},
	actions: {
		showShare() {
			console.log("adfd");
			$(".shade-share").css({"display": "block"});
		},
		hidder(){
			$(".shade-share").css({"display": "none"});
		}
	}
});



// model() {
//   var userInfo = this.modelFor("application");
//   return RSVP.hash({
//     joinedBefors: $.getJSON(config.apiBase + "rankings/last", {
//       userId: userInfo ? userInfo.userId : 'none',
//       gameZoneProductId: 1
//     }),
//     wondBefors: $.getJSON(config.apiBase + "rankings/last", {
//       userId: userInfo ? userInfo.userId : 'none',
//       gameZoneProductId: 2
//     })
//   });
//
// },
